package com.job.springsea.work0702;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author lenovo
 * @version 1.0
 * @since 2022-07-02 17:48:53
 */
public class Work0702 {
    public static void main(String[] args) {
        int[] arr={20,22,7,2,14,57,47};
        Work0702.bubble(arr);
        Work0702.select(arr);
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入参加游戏的人数");
        int n=sc.nextInt();
        int number=Work0702.getVictoryNumbers(n);
        System.out.println("胜利者的编号是"+number);
    }
    public static void bubble(int[] arr){
        int len=arr.length;
        for (int i = 0; i <len-1; i++) {
            for (int j = 0; j <len-1-i ; j++) {
                if(arr[j]<arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
    public static  void select(int[] arr){
        int len=arr.length;
        for (int i = 0; i <len-1-1 ; i++) {
            for (int j = i+1; j <len-1 ; j++) {
                if(arr[i]<arr[j]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        for (int i : arr) {
            System.out.print(i+"\t");
        }
    }
    public static int getVictoryNumbers(int n){
        int[] person =new int[n];
        for (int i = 0; i < n; i++) {
            person[i]=i+1;
        }
        while(person.length>3){
            int[] newPerson= new int[person.length-1];
            for (int i = 3; i <person.length ; i++) {
                newPerson[i-3]=person[i];
            }
            newPerson[newPerson.length-2]=person[0];
            newPerson[newPerson.length-1]=person[1];
            person=newPerson;
        }
        return person[1];
    }
}